<template>
  <div>
    <div class="head" style="width: 1200px">
      <el-form
        :inline="true"
        :model="form"
        class="demo-form-inline"
        @submit.native.prevent
      >
        <el-form-item label="客户名称">
          <el-input
            v-model="form.oname"
            placeholder="输入客户名称:模糊查询"
            @keyup.native.enter="onSubmit"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-divider></el-divider>
    <el-table :data="orders">
      <el-table-column label="订单编号" prop="oid"></el-table-column>
      <el-table-column label="客户姓名" prop="oname"></el-table-column>
      <el-table-column label="到达时间" prop="arrdate"></el-table-column>
      <el-table-column label="离开时间" prop="leavedate"></el-table-column>
      <el-table-column label="价格" prop="oprice"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="primary"
            icon="el-icon-more-outline"
            circle
            @click="$router.push(`/home/order-room/${scope.row.oid}`)"
            title="查看详情"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页器 -->
    <el-pagination
      background
      layout="->,prev, pager, next,total,jumper"
      :current-page="this.page"
      :page-size="this.pagesize"
      :total="this.total"
      @current-change="pageChange"
      style="margin-top: 30px"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      keyword: '',
      form: {
        oname: '',
      },
      page: 1,
      pagesize: 5,
      total: 0,
      orders: [],
    }
  },
  mounted() {
    let params = {
      page: this.page,
      pagesize: this.pagesize,
    }
    this.$http.orderApi.list(params).then(res => {
      console.log(res)
      this.orders = res.data.data
      this.total = res.data.total
    })
  },
  methods: {
    pageChange(page) {
      console.log(page)
      let params = { page: page, pagesize: this.pagesize }
      this.$http.orderApi.list(params).then(res => {
        console.log(res)
        this.orders = res.data.data
      })
    },

    onSubmit() {
      this.keyword = this.form.oname
      if (this.form.oname) {
        let params = {
          oname: this.form.oname,
          page: 1,
          pagesize: this.pagesize,
        }
        this.$http.orderApi.mohu(params).then(res => {
          console.log('131', res)
          this.orders = res.data.data
          this.total = res.data.total
        })
      } else {
        let params = {
          page: this.page,
          pagesize: this.pagesize,
        }
        this.$http.orderApi.list(params).then(res => {
          console.log(res)
          this.orders = res.data.data
          this.total = res.data.total
        })
      }
    },
  },
}
</script>

<style lang="scss" scoped></style>
